package GameServer.net;

import GameServer.Demo;
import GameServer.core.Router;
import GameServer.util.ExecutorPool;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by gzhd on 2017/11/29.
 */
public class NethandlerImpl implements NetHandler {
    @Override
    public void read(JSON request) {
        ExecutorPool.handleThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Demo.print("read:"+request+toString());
                    Router.getInstance().handle(NetFramework.inst,(JSONObject) request);

                } catch (Exception e) {
                    Demo.print(e.getMessage());
                }
            }
        });


    }

    @Override
    public void write(JSON request) {
        Demo.resp(request.toJSONString());
        Demo.print("write:"+request.toJSONString());


    }

    @Override
    public void connect(String host) {

    }

    @Override
    public void disconnect(String host) {

    }

    @Override
    public void exceptionCaught(String host) {

    }
}
